<!-- 员工拉黑名单 -->
<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="姓名" prop="workerName">
        <el-input
          v-model="queryParams.workerName"
          placeholder="请输入姓名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="身份证" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--                v-hasPermi="['worker:block:export']"
-->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['worker:block:export']"
        >导出
        </el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="序号" type="index" align="center"></el-table-column>
      <el-table-column label="姓名" prop="workerName" :show-overflow-tooltip="true" align="center"/>
      <el-table-column label="身份证" min-width="100px" prop="idCard" align="center"></el-table-column>
      <el-table-column label="年龄" prop="age" :show-overflow-tooltip="true" align="center"/>
      <el-table-column label="加入时间" min-width="100px" prop="createTime" align="center" ></el-table-column>
      <el-table-column label="备注" prop="blockRemark" align="center"  min-width="180"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          v-hasPermi="['job:termSchedule:del']" -->
          <el-button size="mini"
                     type="text"
                     icon="el-icon-delete"
                     @click="handleDelete(scope.row)"
                     v-hasPermi="['worker:block:remove']"
          >移除
          </el-button>

        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

</template>

<script>

import {
  removeFromBlock,
  listData,
  exportBlockWorker,
} from "@/api/partTimeJob/workerInfo/workerInfo";
export default {
  name: "workerBlock",
  data() {
    return {
      loading: true,
      //导出加载
      exportLoading:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        creator: undefined,
        deptId: undefined,
        status: undefined
      },
      //表格
      dataList:[],
      // 显示搜索条件
      showSearch: true,
      total:0,

    }
  },
  created() {
    this.getList();
  },
  methods:{
    /** 查询列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(
        response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 检索 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有黑名单员工?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportBlockWorker(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    },
    /** 移除黑名单操作 */
    handleDelete(row){
      let text = '移除黑名单';
      this.$confirm('确认要将' + row.workerName + text+'吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return removeFromBlock(
          {
            workerId:row.workerId,
            workerType:row.workerType
          }
        );
      }).then(() => {
        this.msgSuccess(text + "成功");
        this.getList();
      }).catch(function () {
        this.msgError("操作失败");
      });
    }

  }
}
</script>

<style scoped>

</style>
